package com.jeecms.edu.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.jeecms.edu.entity.SchoolInformation;

/**
 * Servlet implementation class IndexSearch
 */
@WebServlet("/IndexSearch")
public class IndexSearch extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
//		String search=new String(request.getParameter("searchs").getBytes("ISO8859-1"),"UTF-8");
		String search=request.getParameter("searchs");
//		System.out.println(search);
		String callback=request.getParameter("callback");
//		int num=Integer.parseInt(request.getParameter("page"));
		List searchlist=SchoolInformation.searchKeyInfo(search);
		System.out.println(searchlist.size()+" List"+searchlist);
		PrintWriter out = response.getWriter();  
		if (null!=searchlist && searchlist.size()!=0) {
			request.getSession().getServletContext().setAttribute("schoollist", searchlist);
			request.getSession().getServletContext().setAttribute("exadd", search);
			String output = callback + "(0)";  
			response.setContentType("text/javascript");  
			out.println(output);  
		}else{
			String output = callback + "(1)";  
			response.setContentType("text/javascript");  
			out.println(output); 
		}
	}

}
